import {Panel} from 'comps/common';
import ServiceManageList from '../components/service-manager-list';
import {fetchServiceListByMachine} from 'actions/service';
import { getFetchStatus } from 'actions/util';
import * as React from 'react';
import * as ReactRedux from 'react-redux';

const mapStateToProps = (state) => {
  return {
    isFetching: getFetchStatus(state, fetchServiceListByMachine),
    services: state.serviceListByMachine
  };
};

const mapDispatchToProps = (dispatch) => {
  return {
    initFetch: (machineAddress) => {
      dispatch(fetchServiceListByMachine(machineAddress));
    }
  };
};

class MachineDetail extends React.Component {

  componentDidMount() {
    this.props.initFetch(this.props.address);
  }

  render() {
    return (
      <Panel title="服务列表">
        <ServiceManageList {...this.props}/>
      </Panel>
    )
  }
}

export default ReactRedux.connect(mapStateToProps, mapDispatchToProps)(MachineDetail);
